package com.shyroke.service.serviceImpl;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shyroke.entity.FansKey;
import com.shyroke.mapper.FansMapper;
import com.shyroke.service.FansServiceI;

@Service
public class FansServiceImpl implements FansServiceI {

	@Autowired
	private FansMapper fansMapper;
	
	@Override
	public List<FansKey> selectByUserId(Integer id) {
		return fansMapper.selectByUserId(id);
	}

	@Override
	public List<FansKey> selectByFansId(Integer id) {
		return fansMapper.selectByFansId(id);
	}

	@Override
	public void insert(FansKey fans) {
		fansMapper.insert(fans);
	}

	@Override
	public boolean isLook(Integer id, Integer otherUserId) {
		
		List<FansKey> fansKeys = fansMapper.selectByUserId(otherUserId);
		
		List<FansKey> usrList = fansKeys.stream().filter(fans->id==fans.getFansid()).collect(Collectors.toList());
		
		return (usrList!=null&&usrList.size()!=0)?true:false;
	}

}
